package com.mytest;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

/**
 * Hello world!
 *
 */
public class App {

    public static void main( String[] args ) throws Exception {

        //1. 创建连接工厂
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
        //2. 创建连接 并 开启
        Connection connection = connectionFactory.createConnection();
        connection.start();
        //3. 创建Session
        Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
        //4. 创建消息目的地
        Destination destination = session.createQueue("weixin-Queue");
        //5. 创建生产者
        MessageProducer producer = session.createProducer(destination);
        //6. 发送消息
        for (int i=0;i<5;i++){

            TextMessage textMessage = session.createTextMessage("Hello,MQ3"+i);
            producer.send(textMessage);

        }

        //7. 释放资源
        producer.close();
        session.close();
        connection.close();
    }
}
